<!-- D:\project\app\ydz-app-uniapp\static\images\forum -->
<template>
	<view class="pagebody">
		<view class="topbgbox">
		</view>
		<view class="navbox">
			<view class="justify-start align-center ofx" style="height: 116rpx;padding-left: 34rpx;">
				<view @click="checknav(item,index)" style="margin-right: 32rpx;flex-shrink: 0;"
					:class="isnavindex==index?'isnav':'othernav'" v-for="(item,index) in navlist" :key="index">
					{{item.dictLabel}}
					<view v-show="isnavindex==index" class="linediv">
					</view>
				</view>
			</view>
			<view class="flex-row align-center ofx" style="height: 78rpx;padding-left: 24rpx;">
				<view @click="checklm(item,index)" class="fz32 mr16 br48 justify-center align-center"
					:class="islmindex==index?'otherlmitem':'islmitem'" v-for="(item,index) in lmlist"
					style="padding: 16rpx 32rpx;flex-shrink: 0;">
					{{item.dictLabel}}
				</view>
			</view>

		</view>
		<view class="bgfff br24" v-if="topPostlist.length" style="padding: 24rpx ;margin-top: -90rpx; ">
			<view class="" style>
				<ul class="recomlist">
					<li class="recomli" v-for="(item,index) in topPostlist" :key="index">
						<view class="leftno noone">{{index+1}}</view>
						<view class=" righttext lineclamp2" style="" @click="todetail(item)">
							{{item.title}}
						</view>
					</li>

				</ul>
			</view>
		</view>
		<view class="postbox mt16">
			<view class="postcard mt16" style="border-radius: 32rpx;" v-for="(item,index) in postlist" :key="index">
				<view class="">
					<view class="cardtop flex-row justify-between">
						<view class="flex-row">
							<image style="width: 68rpx;height: 68rpx;border-radius: 50%;" :src="baseUrl+item.invAvatar"
								mode="">
							</image>
							<view class="ml16">
								<view class="flex-row">
									<view class="color303b39 fz32">
										{{item.invName}}
									</view>
								</view>
								<view class="mt16" style="color: #7E8987; font-size: 24rpx;">
									{{item.createTime?item.createTime.slice(0,10):item.updateTime.slice(0,10)}}
								</view>
							</view>
						</view>
						<view class="flex-row" @click="openlh(item)">
							<view class="" style="height:6rpx;width: 6rpx;background: #B8C3C1;border-radius: 50%;">
							</view>
							<view class=""
								style="margin: 0 6rpx;height:6rpx;width: 6rpx;background: #B8C3C1;border-radius: 50%;">
							</view>
							<view class="" style="height:6rpx;width: 6rpx;background: #B8C3C1;border-radius: 50%;">
							</view>
						</view>
					</view>
					<view @click="todetail(item)" class="cardtitle color303b39 fwbold"
						style="font-size: 32rpx;margin-top: ;">
						{{item.title}}
					</view>
					<view @click="todetail(item)" class="cardcontent color303b39 mt25 lineclamp4">
						{{item.content}}
					</view>
				</view>
				<!-- 				<view @click="todetail(item)" class="cardimgs flex-row ofx mt25">
					<image v-for="(item,index) in item.attachFiles" :key="index" class="mr16" style="flex-shrink: 0;width: 320rpx;height: 320rpx;border-radius: 16rpx;"
						:src="item.url" mode=""></image>
				</view> -->
				<view @click="todetail(item)" v-if="item.attachFiles.length>0" class="cardimgs flex-row ofx mt25 "
					style="">
					<view v-for="(element,index1) in item.attachFiles" :key="index1" class="imgbox "
						:style="{ background: 'url(' + element.url + ') no-repeat' }">
					</view>
				</view>

				<view class="cardbot justify-around align-center mt25"
					style="height: 96rpx;border-top: 1rpx solid #F4F8F8;">
					<!-- 					<view class="flex-row align-center">
						<image src="../../static/images/forum/share.png"
							style="width: 40rpx;height: 40rpx;margin-right: 16rpx;" mode=""></image>
						分享
					</view> -->
					<view class="flex-row align-center">
						<image @click="clicknice(item)"
							:src="item.isLike?'../../static/images/forum/isnice.png':'../../static/images/forum/nice.png'"
							style="width: 40rpx;height: 40rpx;margin-right: 16rpx;" mode=""></image>
						{{item.likeCount?item.likeCount:0}}
					</view>
					<view class="flex-row align-center">
						<image @click="clicklike(item)"
							:src="item.isCollect?'../../static/images/forum/islike.png':'../../static/images/forum/like.png'"
							style="width: 40rpx;height: 40rpx;margin-right: 16rpx;" mode=""></image>
						{{item.collectCount?item.collectCount:0}}
					</view>
				</view>
			</view>
		</view>
		<view class="addbtn align-center justify-center" @click="addpost" style="">
			+
		</view>
		<u-popup v-model="lhshow" mode="bottom">
			<view class="bgfff" style="padding: 64rpx 41rpx 24rpx;">
				<view class="justify-around align-center">
					<view v-show="!isOwner" @click="tojbpage" class="justify-center align-center flex-col">
						<image src="../../static/images/forum/jubao.png"
							style="width: 56rpx;height: 56rpx;margin-bottom: 16rpx;" mode=""></image>
						<view class="color303b39 ">
							举报
						</view>
					</view>
					<view v-show="isOwner" class="justify-center align-center flex-col" @click="delshow = true">
						<image src="../../static/images/forum/delete.png"
							style="width: 56rpx;height: 56rpx;margin-bottom: 16rpx;" mode=""></image>
						<view class="color303b39 ">
							删除
						</view>
					</view>
				</view>
				<view class="mt40 align-center justify-center" style="height: 100rpx;">
					<span @click="lhshow = false">取消</span>
				</view>
			</view>
		</u-popup>
		<u-modal v-model="delshow" :show-cancel-button="true" :confirm-text="'删除'" @confirm="delpost"
			@cancel="nodelpost" :cancel-text="'取消'" content="是否删除该帖子？"></u-modal>
		<u-toast ref="uToast" />
		<FixedFoot :typeid="1"></FixedFoot>
	</view>
</template>

<script>
	import {
		getInvitationList,
		invlike,
		getDicts,
		invcollectAdd,
		delInvitation
	} from '@/api/api.js'
	import {
		getInfo
	} from '@/api/login'
	import config from '@/config'
	import FixedFoot from '../../layouts/fixedfoot.vue';
	export default {
		components: {
			FixedFoot,
		},
		onLoad() {

		},
		data() {
			return {
				baseUrl: config.baseUrl,
				navlist: [],
				isnavindex: 0,
				navvalue: 0,
				lmlist: [],
				islmindex: 0,
				lmvalue: 0,
				topPostlist: [],
				postlist: [],
				lhshow: false,
				lhdelid: null,
				delshow: false,
				isOwner: false,
				pagenum: 1,
				diseaseId: 0,
				maxpage: 1,
			}
		},
		created() {
			this.getdisid()
			this.getpostlist()
			this.getlmlist()
		},
		mounted() {
			uni.$on('update', function(data) {
			})
		},
		onBackPress(options) {
			this.refreshData();
		},
		onReachBottom() {
			if (this.pagenum < this.maxpage) {
				this.pagenum++
				this.getpostlist()
			}else{
				this.$refs.uToast.show({
					title: '没有更多了~',
				})
			}

		},

		methods: {
			getdisid() {
				getInfo().then(res => {
					this.diseaseId = res.userDocument.diseaseId
				})
			},
			tojbpage() {
				uni.navigateTo({
					url: "/pages/forum/reportpage?type=0&tzid=" + this.lhdelid
				})
			},
			getlmlist() {
				getDicts('post_type').then(res => {
					this.navlist = res.data
					this.navvalue = this.navlist[0].dictValue
					getDicts('nominate_type').then(response => {
						this.lmlist = response.data
						this.lmvalue = this.lmlist[0].dictValue
						this.getToppostList()
					})
				})
			},
			getToppostList() {
				let data = {
					postType: this.navvalue,
					nominate: this.lmvalue,
					pageNum: 1,
					pageSize: 4,
					isAsc: 'asc',
				}
				getInvitationList(data).then(res => {
					this.topPostlist = res.rows
				})
			},
			addpost() {
				uni.navigateTo({
					url: '/pages/forum/addpost'
				})
			},
			checknav(item, index) {
				this.pagenum = 1
				this.maxpage = 1
				this.isnavindex = index
				this.navvalue = item.dictValue
				this.getToppostList()
				this.getpostlist()
			},
			checklm(item, index) {
				this.islmindex = index
				this.lmvalue = item.dictValue
				this.getToppostList()
			},
			getpostlist() {
				let data = {
					"pageNum": this.pagenum,
					"pageSize": 10,
					"orderByColumn": "invitation.nominate DESC,invitation.create_time DESC",
					postType: this.navvalue,
					diseaseid: this.diseaseId
				}
				getInvitationList(data).then(response => {
					this.maxpage = Math.ceil(response.total / 10);
					let arr = response.rows
					this.postlist = arr
					// arr.forEach(item => {
					// 	this.postlist.push(item)
					// })
				})

			},
			todetail(item) {
				uni.navigateTo({
					url: '/pages/forum/forumdetail?id=' + item.id
				})
			},
			clicknice(item) {
				let status = 0
				item.isLike = !item.isLike
				if (item.isLike == true) {
					status = 0
					item.likeCount++
				} else {
					status = 1
					item.likeCount--
				}
				let data = {
					invitationId: item.id,
					status: status
				}
				invlike(data).then(res => {})
			},
			clicklike(item) {
				let status = 0
				item.isCollect = !item.isCollect
				if (item.isCollect == true) {
					status = 0
					item.collectCount++
				} else {
					status = 1
					item.collectCount--
				}
				let data = {
					invitationId: item.id,
					status: status
				}
				invcollectAdd(data).then(res => {})
			},
			openlh(item) {
				this.lhshow = true
				this.lhdelid = item.id
				this.isOwner = item.isOwner
			},
			delpost() {
				delInvitation(this.lhdelid).then(res => {
					this.$refs.uToast.show({
						title: '帖子已删除',
						type: 'success',
					})
					this.lhshow = false
					this.getpostlist()
				})
			},

			nodelpost() {
				this.delshow = false;
			}
		},

	}
</script>

<style lang="scss" scoped>
	.pagebody {
		padding-bottom: 136rpx;
		background: #F0F6F5;

		.topbgbox {
			height: 773rpx;
			background: url(../../static/images/forum/homebg.png) no-repeat;
			background-size: cover;
		}

		.navbox {
			height: 307rpx;
			padding-bottom: 16rpx;
			margin-top: -382rpx;
			background: rgba(0, 151, 124, 0.2);
			box-shadow: 0rpx 0rpx 21rpx 0rpx rgba(18, 223, 183, 0.2), inset 0rpx 16rpx 24rpx 0rpx rgba(0, 255, 209, 0.5);
			border-radius: 32rpx 32rpx 0px 0px;
			border: 2rpx solid #37EEC9;

			.isnav {
				font-weight: bold;
				color: #fff;
				font-size: 36rpx;

				.linediv {
					height: 8rpx;
					width: -webkit-fill-available;
					background: #fff;
					border-radius: 8rpx;
					margin-top: 10rpx;
				}
			}

			.othernav {
				font-size: 32rpx;
				color: #fff;
			}

			.islmitem {
				background: #11B494;
				color: #fff;
			}

			.otherlmitem {
				background: linear-gradient(125deg, #F5FFFD 0%, #DDFFF9 100%);
				color: #00977C;
			}

		}

		.recomlist .recomli:last-child {
			border-bottom: none;
		}

		.recomlist {
			.recomli {
				padding: 24rpx 0;
				display: flex;
				border-bottom: 1rpx dashed #D7DDDC;

				.leftno {
					width: 30rpx;
					height: 30rpx;
					color: #fff;
					font-weight: bold;
					font-size: 24rpx;
					line-height: 30rpx;
					text-align: center;
					border-radius: 6rpx;
					flex-shrink: 0;
					margin-top: 13rpx;
					margin-right: 18rpx;
				}

				.righttext {
					font-family: PingFang SC, PingFang SC;
					font-weight: bold;
					font-size: 36rpx;
					color: #303B39;
					line-height: 56rpx;
					text-align: left;
				}

				.noone {
					background: linear-gradient(357deg, #FC1C12 0%, #FD6F23 100%);
				}

				.notwo {
					background: linear-gradient(357deg, #FC4A14 0%, #FF9F1B 100%);
				}

				.nothree {
					background: linear-gradient(357deg, #FB7511 0%, #FECA18 100%);
				}

				.noother {
					background: #A4AFAD;
				}

			}
		}

		.postbox {
			.postcard {
				background: #fff;
				padding: 48rpx 24rpx 0rpx;

				.cardtop {}

				.cardtitle {
					margin-top: 24rpx;
				}

				.imgbox {
					height: 320rpx;
					width: 320rpx;
					flex-shrink: 0;
					background-size: cover !important;
					border-radius: 16rpx;
					background-position: center !important;
					margin: 0 15rpx 15rpx 0;
				}

			}
		}

		.addbtn {
			position: fixed;
			bottom: 120rpx;
			right: 26rpx;
			width: 88rpx;
			height: 88rpx;
			border-radius: 50%;
			background: linear-gradient(140deg, #4EF2C9 0%, #00D9B2 100%);
			box-shadow: 0px 0px 16px 0px rgba(0, 151, 124, 0.3);
			font-size: 88rpx;
			text-align: center;
			// line-height: 88rpx;
			color: #fff;
		}
	}
</style>